﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;

namespace BlueWind.Mediator.ServiceContracts
{
    [DataContract]
    public class HandSakeBase
    {
        [DataMember]
        private List<String> memberList;

        public HandSakeBase()
        { }

        public HandSakeBase(String from, String to)
        {
            memberList = new List<String>();
            memberList.Add(from);
            memberList.Add(to);
        }

        [DataMember]
        public String HandSakeHash
        {
            get
            {
                memberList.Sort();
                String temp = "";
                foreach (String a in memberList)
                {
                    temp += a;
                }
                return PerfumeRiver.Common.Encryption.MD5.ComputeHash(temp);
            }
            set { ; }
        }

        [DataMember]
        public String HandSakeName
        {
            [OperationContract]
            get
            {
                memberList.Sort();
                String temp = "";
                foreach (String a in memberList)
                {
                    temp += a;
                }
                return temp;
            }
            set { ; }
        }

        public static String GetRoomName(String from, String to)
        {
            var tmp = new HandSakeBase(from, to);
            return tmp.HandSakeName;
        }

        [DataMember]
        public List<String> MemberList
        {
            get
            {
                return memberList;
            }
            set
            {
                memberList = value;
            }
        }

        public bool Equals(HandSakeBase handSake)
        {
            // If parameter is null return false:
            if ((object)handSake == null)
            {
                return false;
            }
            return (HandSakeName == handSake.HandSakeName);
        }
    }
}